package com.multiplayer.service.impl;

import java.util.List;

import com.multiplayer.dao.IAdminDao;
import com.multiplayer.dao.impl.AdminDaoImpl;
import com.multiplayer.entity.Admin;
import com.multiplayer.entity.Emp;
import com.multiplayer.service.IAdminService;
/**
 * 管理员登录注册Service
 * @author zhangwenhao 2020.5.12
 *
 */
public class AdminServiceImpl implements IAdminService{
	IAdminDao adminDao = new AdminDaoImpl();
	@Override
	public boolean adminLogin(String username, String apassword) {
		
		boolean flag = false;
		List<Admin> list = adminDao.queryAdminById(username);
		Admin admin = null;
		if(list.size()>0) {
			for(Admin a:list) {
				admin = a;
			}
			
			if(apassword.equals(admin.getApassword())) {
				//登录成功返回true
				flag = true;
			}else {
				//登录失败返回false
				flag = false;
			}
		}else {
			//用户名不存在直接返回false
			return false;
		}
		return flag;
	}

	@Override
	public boolean adminRegist(String username, String apassword) {
		//1.查询员工表中是否存在这个员工
		List<Emp> list  = adminDao.queryEmp(username);
		//2.查询是否已经存在了注册信息
		List<Admin> list1 = adminDao.queryAdminById(username);
		
		boolean flag = false;
		if(list.size()>0 && list1.size() == 0) {
			//存在员工 且没有注册 添加注册信息
			Admin admin = new Admin(username, username, apassword);
			flag = adminDao.addAdmin(admin);
		}else {
			//不存在直接返回false
			return false;
		}
		return flag;
	}

	@Override
	public boolean adminLoginByFace(String face, String type) {
		
		return false;
	}


}